package com.study.demo_test;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.study.demo_test.bean.Book;
import com.study.demo_test.service.HelloService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class DemoTestApplicationTests2 {
    @Autowired
    TestRestTemplate template;

    @Test
    public void getTest() {
        String ws = template.getForObject("/hello?name={1}", String.class, "ws");
        System.out.println(ws);
    }

    @Test
    public void postTest() throws JsonProcessingException {
        Book book = new Book();
        book.setId(1);
        book.setAuthor("罗贯中");
        book.setName("三国");
        ResponseEntity<Book> bookResponseEntity = template.postForEntity("/book", book, Book.class);
        System.out.println(bookResponseEntity.getBody());
    }
}
